/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * main.c
 */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "engine/common.h"
#include "engine/launcher.h"

static void usage(const char *argv0) {
    fprintf(stderr, "Usage: %s [-c componentPath][-r repositories]\n", argv0);
    //resource type: module component package
    exit(EXIT_FAILURE);
}

int main(int argc, char **argv) {
    sys_memory_init();
    char *logConfigFilePath = append_path(getenv(FUNNY_HOME), "/log/zlog.conf");
    if (!log_init(logConfigFilePath)) {
        return -1;
    }

    // log_info("my_cat", "hello, zlog");

    LaunchArgs *args = (LaunchArgs *)sys_malloc(sizeof(LaunchArgs));
    args->component = NULL;
    args->repositories = NULL;

    int opt;
    while ((opt = getopt(argc, argv, "c:r:")) != -1) {
        switch (opt) {
            case 'c':
                args->component = optarg;
                break;
            case 'r':
                args->repositories = optarg;
                break;
            default:
                usage(argv[0]);
        }
    }

    launch(args);

    log_finish();
    sys_memory_finish();
    return 0;
}
